package com.zaoniao.enstudy.api.dto;

import com.zaoniao.enstudy.domain.entity.ExamAnswer;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.NotBlank;

/**
 * 考试明细答题入参dto.
 */
@Data
@Schema(name = "考试明细答题入参dto")
public class AnswerDto
{
    /**
     * 考试记录id
     */
    @Schema(description = "考试记录id", name = "examPaperId")
    @NotBlank(message = "考试记录id不能为空")
    private Integer examPaperId;

    @Schema(description = "答题明细唯一标识", name = "examAnswerId")
    @NotBlank(message = "答题Id不能为空")
    private Integer examAnswerId;

    @Schema(description = "用户答题选项", name = "answer")
    @NotBlank(message = "答题选项不能为空")
    private String answer;

    @Schema(description = "答题单词", name = "word")
    @NotBlank(message = "答题单词不能为空")
    private String word;

    @Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
    public interface Converter {

        AnswerDto.Converter INSTANCE = Mappers.getMapper(AnswerDto.Converter.class);

        @Mapping(source = "examAnswerId", target = "id")
        @Mapping(source = "answer", target = "userAnswer")
        ExamAnswer dto2do(AnswerDto answerDto);

    }
}
